package src.ihm;

import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.SQLException;
import java.util.Timer;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;

import src.client.CommunicationClient;

public class PannConnexion extends JPanel{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JButton seConnecter;
	private JLabel email;
	private JTextField emailTexte;
	private JLabel motDePasse;
	private JPasswordField mDpTexte;
	private JButton connection;
	
	public PannConnexion()
	{
		
		FlowLayout flow1=new FlowLayout(FlowLayout.CENTER,200,15);
		setLayout(flow1);
		seConnecter=new JButton("Se connecter");
		add(seConnecter);
		email=new JLabel("Adresse mail :");
		add(email);
		emailTexte=new JTextField(20);
		add(emailTexte);
		motDePasse=new JLabel("Mot de passe :");
		add(motDePasse);
		mDpTexte=new JPasswordField(20);
		add(mDpTexte);
		connection=new JButton("Connection");
		add(connection);
		connection.setVisible(false);
		email.setVisible(false);
		emailTexte.setVisible(false);
		motDePasse.setVisible(false);
		mDpTexte.setVisible(false);
		seConnecter.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				email.setVisible(true);
				emailTexte.setVisible(true);
				motDePasse.setVisible(true);
				mDpTexte.setVisible(true);
				connection.setVisible(true);
				seConnecter.setVisible(false);
			}
		});
		
		//Appui sur le bouton connection
		connection.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {
				boolean connecte=false;
				connection.setEnabled(false);
				String mail=emailTexte.getText();
				String password=mDpTexte.getText();
				CommunicationClient comm=new CommunicationClient(mail,password,1);
				comm.start();
				while(comm.connection!=true)
				{
				}
				FenetrePrincipale fenP=new FenetrePrincipale(mail);
				
			}
		});
	}
	

}
